<template>
  <div></div>
</template>
<script>
import api from "api/api.js";
import Cookie from "js-cookie";
import {
  sessionSetItem,
  sessionGetItem,
  sessionRemoveItem
} from "util/index.js";
import { getAuth } from "util/getAuth.js";

const isDev = process.env.NODE_ENV == "dev" ? true : false;
export default {
  name: "init",
  data() {
    return {};
  },
  methods: {
    init() {
      let token = sessionGetItem("token");
      console.log(token);
      if (token) {
        console.log("token存在，跳转index");
        this.$router.replace("/index");
      } else {
        console.log("token不存在");
        // getAuth();
      }
    },
    async testInit() {
      this.$router.replace("/index");
      return;
      const res = await api.getTestToken();
      if (res.code === "0000") {
        sessionSetItem("token", res.result);
        this.$router.replace("/index");
      } else {
        console.error("测试token不存在");
      }
    }
  },
  created() {
    if (isDev) {
      console.log("init页测试环境执行testInit方法");
      this.testInit();
    } else {
      console.log("init页生产环境执行init方法");
      this.init();
    }
  }
};
</script>
